home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Online / Epic4 / share / epic / help / 5_programming / foreach < prev    next >
Encoding:
Text File  |  2001-03-21  |  1.5 KB  |  44 lines

  1. Synopsis:
  2.    foreach [-]<structure> <variable> { <action> }
  3.  
  4. Description:
  5.    The FOREACH command is a loop type that iterates through the items in
  6.    a variable (or alias, see below) structure.  This is often useful for
  7.    purging an entire structure, or for searching through it for a certain
  8.    piece of data.
  9.  
  10.    Variables in the action field are normally not expanded until actual
  11.    execution of the action.  They can be forced to expand early by quoting
  12.    the opening curly brace with a backslash: \{
  13.  
  14.    If a hyphen (-) is prepended to the structure name, the FOREACH loop
  15.    will try to iterate through an alias structure instead of a variable
  16.    structure.  This is primarily useful for purging alias structures.
  17.  
  18. Examples:
  19.    Simple usage of FOREACH, assuming $blah is a structure two levels deep:
  20.       foreach blah xx {
  21.          foreach blah.${xx} yy {
  22.             echo $blah[$xx][$yy]
  23.          }
  24.       }
  25.  
  26.    To purge an alias structure called booya:
  27.       foreach -booya xx {
  28.          alias -booya[$xx]
  29.       }
  30.  
  31. See Also:
  32.    fe(5); fec(5); until(5); while(5)
  33.  
  34. Restrictions:
  35.    Structures may be referenced as either $var.${subvar}.${subvar} or
  36.    $var[$subvar][$subvar] (with any number structure levels, of course).
  37.    The notation $var.$subvar.$subvar parses as $var[${subvar.$subvar}],
  38.    which of course is incorrect, and should not be used.
  39.  
  40. Other Notes:
  41.    The action portion does not necessarily need to do anything, though there
  42.    isn't much point in using the command without it.
  43.  
  44.